<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="../vue.2.5.1.js"></script>
</head>

<body>
    <div id='app'>
        <p ref='p'></p>
        <button @click='handleRef'>通过ref获取子组件实例</button>
        <div>{{message1}}</div>
        <component-a ref='comA'></component-a>
    </div>
    <script>
        // 【2】子传父，在父组件中访问子组件，并抓取子组件的data
        Vue.component('component-a', {
            template: '<div>子组件</div>',
            data() {
                return {
                    message: "子组件内容"
                }
            }
        });
        var app = new Vue({
            el: '#app',
            data: {
                message1: '22'
            },
            methods: {
                handleRef() {
                    var msg = this.$refs.comA.message;
                    console.log(msg);
                    this.message1 = msg;

                }
            }
        })
    </script>

</body>

</html>